<?php
session_start();
require_once 'model/users.php';
require_once 'template/log_admin.php';
$md_users = new Users();
$users = $md_users->select();
?>
<link rel="stylesheet" type="text/css" href="public/css/style.css" />
<div class="container">
    <?php include 'template/header.php'; ?>
    <form method="POST" align="center">
        Username: <input type="text" name="username"><br>
        Password: <input type="password" name="password"><br>
        <input type="submit" name="submit" value="Login">
    </form>
</div>
<?php
if (isset($_POST['submit'])) {
    $login = array(
        'username' => $_POST['username'],
        'password' => $_POST['password']
    );
    $isOk = FALSE;
    for ($i = 0; $i < count($users); $i++) {
        if ((strcmp($login['username'], $users[$i]['name']) == 0) &&
                (strcmp(md5($login['password']), $users[$i]['password']) == 0)) {
            $isOk = TRUE;
            break;
        }
    }
    if ($isOk) {
        $_SESSION['id'] = TRUE;
        ?>
        <h3 align="center">admin dang nhap: <?php echo mwriteLog(); ?></h3>
        <?php
        echo '<a href="index.php"><h3 align="center">Back</h3></a>';
    }else
        echo 'loi';
}
?>